<?php
/**
 * @author billy Gao <345501225@qq.com>
 */
namespace Home\Controller;
class AddtimemsgController extends BaseController {
    /**
     * 添加到期提醒短信
     */
    public function expire() {
        
        $this->signat = $this->signatures;
        $this->display();
    }
    /**
     * 执行到期短信提醒添加
     */
    public function addExpire() {
        $data['uid'] = $this->userinfo['id'];
        $data['nod'] = intval(I('post.nod'));
        $data['msgcontent'] = I('post.msgcontent');
        $data['signature'] = I('post.sign');
        $data['sendtime'] = I('post.sendhour').":".I('post.sendminute').":00";
        empty($data['msgcontent']) && $this->error('非法操作，请输入短信内容');
        $expire = D('Expiremsg');
        if ($expire->addExpire($data)) {
            $this->success('添加成功', U('Addtimemsg/expire'));
        } else {
            $this->error('添加失败',U('Addtimemsg/expire'));
        }
    }
    /**
     * 查看到期短信
     */
    public function seeExpire() {
        $expire = D('Expiremsg');
        $where['uid'] = $this->userinfo['id'];
        $count      = $expire->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,C('PAGE_LIST'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig("prev", "上一页");
        $Page->setConfig("next", "下一页");
        $Page->setConfig("theme", "%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $limit = $Page->firstRow.','.$Page->listRows;
        $this->expireData = $expire->getExpires($where, $limit);
        $this->page = $Page->show();
        $this->display();
    }
    /**
     * 到期短信删除
     */
    public function delExpire() {
        $where['id'] = intval(I('get.expid'));
        $where['uid'] = $this->userinfo['id'];
        $expire = D('Expiremsg');
        if ($expire->delExpires($where)) {
           echo json_encode(array('msg'=>'success')); 
        } else {
            echo json_encode(array('msg'=>'error'));
        }
        
    }
    
}
